<?php

namespace App\Admin\Forms;

use App\Jobs\HospitalNotice;
use Dcat\Admin\Widgets\Form;
use App\Admin\Field\IntervalWeekNum;
use App\Models\HospitalAppointInterval;
use App\Models\HospitalAppointIntervalNum;
use App\Models\HospitalAppointStreet;
use App\Models\Notice;
use App\Models\Street;
use Illuminate\Support\Facades\DB;

class NoticeForm extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {

        try {
            $article_id = $input['article_id'];
            $hospital_id = $input['hospital_id'];

            $model = new Notice();
            $model->article_id = $article_id;
            $model->hospital_id = $hospital_id;
            $model->type = $input['type'];
            $model->save();

            HospitalNotice::dispatch($model);
            return $this->response()->success('成功');

        }catch (\Exception $exception){
            return $this->response()->error($exception->getMessage());
        }


    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->hidden('article_id');
        $this->hidden('hospital_id');
        $this->select('type','选择人群')->options(Notice::$typeTxt);

    }

        /**
         * The data of the form.
         *
         * @return array
         */
        public function default()
        {
            return [
                'name'  => 'John Doe',
                'email' => 'John.Doe@gmail.com',
            ];
        }
}
